package com.mininglamp.action;

import javax.validation.Valid;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.mininglamp.model.Goods;
import com.mininglamp.service.GoodsService;
import com.mininglamp.utils.Pager;
import com.mininglamp.utils.ResultMsg;

@RestController
@RequestMapping("/goods")
public class GoodsAction {
	
	@Autowired
	GoodsService goodsService;
	
	/**
	 * 插入商品信息
	 * @param goods
	 * @return
	 */
	@PostMapping(value="/insert")
	public ResultMsg inserGoods(@RequestBody Goods goods){
		String result = "";
		if(goodsService.inserGoods(goods)==1){
			result = "success";
		}else{
			result = "fail";
		}
		return ResultMsg.success(result);
		
	}
	
	/**
	 * 查询分页商品信息
	 * @param pager
	 * @param wetchatsId
	 * @return
	 */
	@GetMapping(value="/searchPage/{wetchatsId}")
	public Pager searchGoodsPage(@Valid Pager pager,@PathVariable String wetchatsId){
		
		return goodsService.searchGoodsPage(pager, wetchatsId);
		
	}
}
